package com.ehome.poct.terminal.api.fegin;

import com.ehome.feign.annotation.IgnoreFeignResponseAdvice;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.net.URI;

/**
 * 合伙人 rpc
 *
 * @author cq
 * @since 2022/06/13 16:34
 **/
@Component
@RefreshScope
@RequiredArgsConstructor
public class AgentRpcImpl implements AgentRpc{
    private final  AgentClient agentClient;
    @Value("${agent.url}") private String agentUrl;

    /**
     * 算法分析
     *
     * @param agentId
     * @return
     */
    @Override
    public String  getAgentInfo(Long agentId) {
       return agentClient.getAgentInfo(URI.create(agentUrl), agentId);
    }


    @FeignClient(value = "AgentClient", contextId = "AgentClient")
    interface AgentClient {
        /**
         * 算法分析
         *
         * @param uri
         * @param  agentId
         * @return
         */
        @IgnoreFeignResponseAdvice
        @GetMapping("/queryParentAgentInfoById/{agentId}")
        String getAgentInfo(URI uri, @PathVariable Long agentId);
    }

}
